import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Language } from "../../../../../extend/language/Language";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { TilePanel } from "../../equipment/TilePanel";
import { PetExplorePackItemCellRenderer } from "./PetExplorePackItemCellRenderer";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetExplorePackWindow
    
    export  class PetExplorePackWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.datap = new DataProvider();
            this.setSize(355, 260);
            titleHeight = 58;
            title = Language.getString(54479);
            NetDispatcher.addCmdListener(ServerCommand.PetExplorePackCommand, this.onPetExplorePackItemUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.PetExplorePackItemUpdate, this.onPetExplorePackItemUpdateHandler);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            super.createChildren();
            ObjCreate.createTextField(Language.getString(54480), 23, 40, 50, 20, this);
            this._capacityTxt = ObjCreate.createTextField("0/21", 62, 40, 200, 20, this);
            this._capacityTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(20, 70, 315, 140, this);
            var loc2=0;
            while (loc2 < 21) 
            {
                loc1 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
                loc1.width = 38;
                loc1.height = 38;
                this.addChild(loc1);
                loc1.x = 28 + loc2 % 7 * 43;
                loc1.y = 78 + Math.floor(loc2 / 7) * 43;
                ++loc2;
            }
            this._itemsList = new TilePanel();
            this._itemsList.verticalGap = 0;
            this._itemsList.horizontalGap = 0;
            this._itemsList.columnWidth = 43;
            this._itemsList.rowHeight = 43;
            this._itemsList.setSize(320, 130);
            this._itemsList.setStyle("cellRenderer", PetExplorePackItemCellRenderer);
            this._itemsList.move(30, 80);
            this._itemsList.addEventListener(ListEvent.ITEM_CLICK, this.onItemClickHandler);
            this.addChild(this._itemsList);
            this._getAllBtn = ObjCreate.createGButton(Language.getString(54481), 265, 38, 70, 24, this);
            this._getAllBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetAllBtnClickHandler);
            this._tipTxt = ObjCreate.createTextField("", 30, 215, 50, 20, this);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.htmlText = Language.getString(54482);
            return;
        }

        /* internal  */onGetAllBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreGetItem));
            return;
        }

        /* internal  */onItemClickHandler(arg1: ListEvent): void
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=arg1.item as ItemData;
            if (loc2) 
            {
                loc1[loc2.uid] = loc2.itemAmount;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreGetItem, loc1));
            }
            return;
        }

        /* internal  */onPetExplorePackItemUpdateHandler(arg1: Object): void
        {
            var loc3=null;
            var loc1=Cache.instance.pack.petExplorePackCache;
            var loc2=loc1.getAllItems();
            this.datap.removeAll();
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                if (loc3 = loc2[loc4] as ItemData) 
                {
                    this.datap.addItem(loc3);
                }
                ++loc4;
            }
            this._itemsList.dataProvider = this.datap;
            this._capacityTxt.text = this.datap.length + "/" + loc1.sbag.capacity;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.onPetExplorePackItemUpdateHandler(null);
            return;
        }

        /* internal */ /* var */_capacityTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getAllBtn: GButton;

        /* internal */ /* var */_itemsList: TilePanel;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */datap: DataProvider;
    }
